import api from './index'

export interface Teacher {
  id: number
  username: string
  name: string
  email: string
  role: string
  status: string
  course_permissions: Array<{
    id: number
    name: string
  }>
  created_at: string
}

export interface AddTeacherRequest {
  username: string
  password: string
  name: string
  email: string
  courseIds: number[]
}

export interface UpdateTeacherRequest {
  name?: string
  email?: string
  status?: string
}

export interface UpdateTeacherPermissionsRequest {
  courseIds: number[]
}

export interface BatchAddTeacherRequest {
  teachers: Array<{
    username: string
    password?: string
    name: string
    email: string
  }>
}

export const teachersApi = {
  // 获取教师列表
  getTeachers(): Promise<Teacher[]> {
    return api.get('/teachers')
  },

  // 添加教师
  addTeacher(data: AddTeacherRequest): Promise<Teacher> {
    return api.post('/teachers', data)
  },

  // 批量添加教师
  batchAddTeachers(data: BatchAddTeacherRequest): Promise<any> {
    return api.post('/teachers/batch', data)
  },

  // 更新教师信息
  updateTeacher(teacherId: number, data: UpdateTeacherRequest): Promise<Teacher> {
    return api.put(`/teachers/${teacherId}`, data)
  },

  // 更新教师权限
  updateTeacherPermissions(teacherId: number, data: UpdateTeacherPermissionsRequest): Promise<void> {
    return api.put(`/teachers/${teacherId}/permissions`, data)
  },

  // 删除教师
  deleteTeacher(teacherId: number): Promise<void> {
    return api.delete(`/teachers/${teacherId}`)
  }
}
